#ifndef SEQIOT_Z_LOGGER_H
#define SEQIOT_Z_LOGGER_H

#include <errno.h>
#include <string.h>
#include <log4c.h>

extern _Bool running;

void log_init();

void log_fini();

void log_category_location(const log4c_location_info_t *loc_info, int priority, const char *format, ...);

#define log_trace(format, args...) do {\
    const log4c_location_info_t loc_info = LOG4C_LOCATION_INFO_INITIALIZER(NULL);\
    log_category_location(&loc_info, LOG4C_PRIORITY_TRACE, format, ##args);\
} while(0)

#define log_debug(format, args...) do {\
    const log4c_location_info_t loc_info = LOG4C_LOCATION_INFO_INITIALIZER(NULL);\
    log_category_location(&loc_info, LOG4C_PRIORITY_DEBUG, format, ##args);\
} while(0)

#define log_warn(format, args...) do {\
    const log4c_location_info_t loc_info = LOG4C_LOCATION_INFO_INITIALIZER(NULL);\
    log_category_location(&loc_info, LOG4C_PRIORITY_WARN, format, ##args);\
} while(0)

#define log_info(format, args...) do {\
    const log4c_location_info_t loc_info = LOG4C_LOCATION_INFO_INITIALIZER(NULL);\
    log_category_location(&loc_info, LOG4C_PRIORITY_INFO, format, ##args);\
} while(0)

#define log_error(format, args...) do {\
    const log4c_location_info_t loc_info = LOG4C_LOCATION_INFO_INITIALIZER(NULL);\
    log_category_location(&loc_info, LOG4C_PRIORITY_ERROR, format, ##args);\
} while(0)

#define log_errno() do {\
    const log4c_location_info_t loc_info = LOG4C_LOCATION_INFO_INITIALIZER(NULL);\
    log_category_location(&loc_info, LOG4C_PRIORITY_ERROR, "errno=%d, %s", errno, strerror(errno));\
} while(0)

#endif //SEQIOT_Z_LOGGER_H
